const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    avatarUrl: defaultAvatarUrl,
    nickname: '',
  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    console.log(e.detail)
    this.setData({
      avatarUrl,
    })
  },
  onSave(e) {
    var that = this;
    let nickname = e.detail.value.nickname.trim()
    if (nickname == null || nickname == "") {
      wx.showToast({
        title: "昵称不能为空",
        icon: 'error',
        duration: 2000
      })
      return;
    }
    that.setData({
      nickname,
      avatarUrl: that.data.avatarUrl
    })
    console.log("头像：" + that.data.avatarUrl);
    console.log("昵称：" + that.data.nickname);//保存头像和昵称到缓存区中

    wx.setStorageSync('data', that.data)
    wx.switchTab({
      url: '/pages/search_1/search_1',
    })
  },
})